
package com.shop.cloud.mall.api.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shop.cloud.common.core.util.R;
import com.shop.cloud.common.portal.annotation.ApiLogin;
import com.shop.cloud.common.portal.util.ThirdSessionHolder;
import com.shop.cloud.mall.common.entity.UserBill;
import com.shop.cloud.mall.api.service.UserBillService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

/**
 * 用户发票
 *
 * @author
 * @date 2023-04-14 11:00:31
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/userbill")
@Tag(description = "userbill", name = "用户发票API")
public class UserBillController {

    private final UserBillService userBillService;

    /**
     * 用户发票分页列表
     * @param page 分页对象
     * @param userBill 用户发票
     * @return
     */
    @Operation(summary = "用户发票分页列表")
    @GetMapping("/page")
	@ApiLogin
    public R getPage(Page page, UserBill userBill) {
		userBill.setUserId(ThirdSessionHolder.getUserId());
        return R.ok(userBillService.page(page, Wrappers.query(userBill)));
    }

    /**
     * 用户发票新增、修改
     * @param userBill 用户发票
     * @return R
     */
    @Operation(summary = "用户发票新增、修改")
    @PostMapping
	@ApiLogin
    public R save(@RequestBody UserBill userBill) {
		userBill.setUserId(ThirdSessionHolder.getUserId());
        return R.ok(userBillService.saveOrUpdate(userBill));
    }


    /**
     * 用户发票删除
     * @param id
     * @return R
     */
    @Operation(summary = "用户发票删除")
    @DeleteMapping("/{id}")
	@ApiLogin
    public R removeById(@PathVariable String id) {
        return R.ok(userBillService.removeById(id));
    }

}
